﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Proggy.Web.Cms.Controllers;
using System.Web.Mvc;
using Proggy.Web.Cms.Core.Models;
using Proggy.Web.Cms.Core.Configuration;
using Proggy.Web.Cms.PropertyTypes;
using Newtonsoft.Json;

namespace Proggy.Web.Cms.Core.Controllers.PropertyType
{
    public class DragAndDropNoAuthController : ProggyControllerBase
    {
        [ChildActionOnly]
        [HttpGet]
        public PartialViewResult RenderFrontEndPartial(AddedDragAndDropItem model)
        {
            try
            {

                // get type
                var type = DragAndDropManager.DragAndDropPartsCache.Single(x => x.Name == model.PartName);

                // get rendermodel
                var renderModel = (IAutoRenderPropertyType)JsonConvert.DeserializeObject(model.ConfigData, type.PropertyType);

                // 
                return PartialView(renderModel.FullPathToAutoRenderPartial, renderModel.GetAutoRenderModel());
            }
            catch
            {
                return null;
            }

        }
    }
}
